/*
ID:luongho3
LANG:C++
TASK:milk2
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin("milk2.in");
ofstream fout("milk2.out");
struct interval {
       int from;
       int to;     
};
bool compare(interval a,interval b) {
     return (a.from==b.from?(a.to<b.to):a.from<b.from);    
}
int nInterval;
vector<interval> intervals;
main() {
       fin>>nInterval;
       int i,max;
       max=0;
       for (i=0;i<nInterval;++i) {
           interval newItv;
           fin>>newItv.from>>newItv.to;
           intervals.push_back(newItv);
           if (intervals[i].to-intervals[i].from>=max)
              max=intervals[i].to-intervals[i].from;
       }
       sort(intervals.begin(),intervals.end(),compare);
       for (i=0;i<nInterval-1;++i) {
           if (intervals.at(i).to>=intervals[i+1].from) {
              intervals[i+1].from=intervals[i].from;
              if (intervals[i].to>=intervals[i+1].to)
                 intervals[i+1].to=intervals[i].to;
              else
                  intervals[i].to=intervals[i+1].to;
              if (intervals[i].to-intervals[i].from>=max)
                 max=intervals[i].to-intervals[i].from;
           }
       }
       fout<<max<<" ";
       max=0;
       for (i=0;i<nInterval-1;++i) {
           if (intervals[i+1].from-intervals[i].to>=max)
              max=intervals[i+1].from-intervals[i].to;
       }
       fout<<max<<"\n";
       return 0;      
}
